﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OnlineMovieTicket.Data.Repository
{
    public class CinemaTimeTableRepository : IRepository.ICinemaTimeTableRepository
    {
        ONLINEMOVIETICKETEntities dataContent;

        public CinemaTimeTableRepository()
        {
            dataContent = new ONLINEMOVIETICKETEntities();
        }

        public List<Model.CinemaTimeTable> GetTimeTableByCinemaHall(int cinemaHallID)
        {
            var data = (from d in dataContent.CinemaTimeTables
                       where d.CinemaHallID == cinemaHallID
                       select new Model.CinemaTimeTable
                       {
                           CinemaHallID = d.CinemaHallID,
                           ScheduleID = d.ScheduleID,
                           startTime = d.StartTime
                       }).ToList();
            return data;
        }

        public List<Model.CinemaTimeTable> GetAvailableTimeTableByCinemaHall(int cinemaHallID, DateTime showingDate)
        {
            var data = (from d in dataContent.CinemaTimeTables                        
                        where d.CinemaHallID == cinemaHallID
                        && !(from m in dataContent.MovieTimeTables
                             where m.ShowingDate == showingDate
                            select m.ScheduleID).Contains(d.ScheduleID)
                        select new Model.CinemaTimeTable
                        {
                            CinemaHallID = d.CinemaHallID,
                            ScheduleID = d.ScheduleID,
                            startTime = d.StartTime
                        }).ToList();
          
            return data;
        }

        
    }
}
